<template>
	<view class="content">
		<view class="details-header">
			<image @click="goBack"
				src="https://zzboomcos-1317756147.cos.ap-nanjing.myqcloud.com/blind-box/94321725868587882.png" mode="">
			</image>
		</view>
		<view class="userInfo">
			<view class="userImg">
				<image :src="userInfo.headimg" mode=""></image>
			</view>
			<view class="userName">{{userInfo.name}}</view>
			<view class="userId">{{userInfo.userId}}</view>
			<view class="giftReminder">
				TA赠送给您下面奖品，请查收：
			</view>
			<view class="btn-box">
				<span class="u-btn" v-if="status == 3" @click="application()">申请领取</span>
				<span class="u-btn u-info-btn" v-else-if="status == 2">待赠送人确认</span>
				<span class="u-btn u-success-btn" v-else-if="status == 1">领取成功</span>
				<span class="u-btn u-info-btn" v-else>已失效</span>
			</view>
		</view>
		<view class="prize_box">
			<view class="prize_title">
				奖品信息
			</view>
			<view class="u-flex" v-for="(item,index) in prize" :key="index">
				<view class="img_box">
					<image :src="item.detailImages" mode=""></image>
				</view>
				<view class="">
					<p class="parize_name">{{item.name}}</p>
					<p>数量x{{item.num}}</p>
				</view>
			</view>
		</view>
	</view>
</template>


<script>
	import {
		selectSku,
		compliment
	} from "@/api/myBox.js";
	import {
		$getStorage,
		$setStorage,
		$removeStorage
	} from "@/utils/auth.js";
	export default {
		data() {
			return {
				userInfo: {}, // 用户信息
				prize:[], // 奖品信息	
				key:"",
				status:3,
			};
		},
		onLoad(e) {
			console.log(e)
			this.key = e.key
			$removeStorage("rewardKey")
		},
		mounted() {
			this.init()
		},
		methods: {
			init() {
				let data = {
					key:this.key
				}
				selectSku(data).then((res) =>{
					if(res.code == 200){
						this.userInfo = res.data.user;
						this.prize = res.data.sku;
						this.status = res.data.status;
					}
				})
			},
			goBack(){
				uni.navigateTo({
					url: '/pages/myBox/index'
				})
			},
			application(){
				if(this.status != 3){
					return
				}
				let data = {
					key:this.key
				}
				compliment(data).then(res =>{
					if(res.code == 200){
						uni.showToast({
							title: res.message,
							duration: 2000
						});
						this.init()
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 2000
						});
						this.init()
					}
				})
			}
		},
	};
</script>

<style scoped lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		background-color: #fafafa;
		height: 100vh;
		overflow: hidden;
	}
	.details-header{
		width:100%;
		height: 60rpx;
		display:flex;
		align-items: center;
		image{
			width: 40rpx;
			height: 40rpx;
			margin-left: 20rpx;
		}
	}

	.userInfo {
		text-align: center;
	}

	.userImg {
		padding-top: 200rpx;

		image {
			width: 200rpx;
			height: 200rpx;
			border-radius: 50%;
		}
	}

	.userName {
		font-size: 28rpx;
		margin-top: 40rpx;
		color: #333;
	}

	.userId {
		margin-top: 40rpx;
		color: #999;
	}

	.giftReminder {
		font-size: 24rpx;
		font-weight: bold;
		margin-top: 80rpx;
		margin-bottom: 50rpx;
	}

	.btn-box {
		height: 60rpx;
		line-height: 60rpx;
		overflow: hidden;
		box-sizing: border-box;
		padding: 0 40rpx;
		margin-bottom: 80rpx;

		.u-btn {
			height: 100%;
			width: 100%;
			color: #fff;
			background-color: #6c43ff;
			font-size: 24rpx;
			border-radius: 6rpx;
			display: inline-block;
		}
		.u-info-btn{
			background-color: #909399;
			color: #fff;
		}
		.u-success-btn{
			color: #fff;
			background-color: #e6a23c;
		}
	}
	.prize_box{
		flex: 1;
		background-color: #fff;
		border-top-left-radius: 40rpx;
		border-top-right-radius: 40rpx;
		padding: 40rpx;
	}
	.prize_title{
		font-size: 28rpx;
		color: #333;
		font-weight: bold;
		margin-bottom: 30rpx;
	}
	.u-flex{
		display: flex;
		align-items: center;
	}
	.img_box{
		width: 230rpx;
		height: 200rpx;
		image {
			width: 200rpx;
			height: 200rpx;
			border-radius: 20rpx;
		}
	}
	.parize_name{
		margin-bottom: 50rpx;
	}
</style>
